import React from 'react';
import {Checkbox} from 'antd';
import {WeaSearchGroup, WeaFormItem} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import EType from './base/EType';
import ETitle from './base/ETitle';
import EShowNum from './base/EShowNum';
import EShowHeader from './base/EShowHeader';
//import EField from './base/EField';
//  import EField_New from './base/EField_New';
import EField_New from './base/EField_Contacts';

// 通讯录
export default class Content_contacts extends React.Component {
    state = {
        eShowSubordinates: this.props.eShowSubordinates,
        eFieldNewDataSource: this.props.eFieldNewDataSource,
        options: this.props.options,
        optionsinfo: this.props.optionsinfo,
        eFieldNewUsedKeys: this.props.eFieldNewUsedKeys,
        eFieldNewVisible: false,
    };

    render() {
        const {eShowSubordinates, eFieldNewDataSource, options, eFieldNewUsedKeys, eFieldNewVisible, optionsinfo} = this.state;

        let EShowSubordinates = <div></div>;
        if (this.props.eShareLevel == '2') {
            EShowSubordinates = (
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@j4aec8`} label={getLabel(83783, '显示下级下属')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                    <Checkbox ecId={`${this && this.props && this.props.ecId || ''}_Checkbox@z1as4l`} size="default" checked={eShowSubordinates} onChange={e => this.setState({eShowSubordinates: e.target.checked})}/>
                </WeaFormItem>
            );
        }

        let EFieldNewshow = <div></div>;
        let EFieldNew = <div></div>;
        if (eFieldNewVisible) {
            const eFieldNewProps = {
                eFieldNewDataSource: _.cloneDeep(eFieldNewDataSource),
                eFieldNewUsedKeys: _.cloneDeep(eFieldNewUsedKeys),
                options: _.cloneDeep(options),
                optionsinfo: _.cloneDeep(optionsinfo),
                onOk: (data) => {
                    this.setState({
                        eFieldNewDataSource: _.cloneDeep(data.eFieldNewDataSource),
                        eFieldNewUsedKeys: _.cloneDeep(data.eFieldNewUsedKeys),
                        eFieldNewVisible: false
                    });
                },
                onCancel: () => {
                    this.setState({
                        eFieldNewVisible: false
                    });
                }
            };
            EFieldNewshow = (
                <EField_New ecId={`${this && this.props && this.props.ecId || ''}_EField_New@bqy7b8`} {...eFieldNewProps}/>
            );
        }
        const eFieldNewUsedNames = [];
        for (let i = 0; i < eFieldNewUsedKeys.length; i++) {
            for (let j = 0 ; j < eFieldNewDataSource.length; j++) {
                if (eFieldNewUsedKeys[i] == eFieldNewDataSource[j].key) {
                    eFieldNewUsedNames.push(eFieldNewDataSource[j].name);
                }
            }
        }
        
        EFieldNew = this.props.eShareLevel == '2' ? (
            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@5sglh8`} label={getLabel(19495, '显示字段')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                {EFieldNewshow}
                <div style={{height: '30px', lineHeight: '23px'}}>
                    <i className="icon-coms-Flow-setting portal-esetting-btn" onClick={() => this.setState({eFieldNewVisible: true})}/>
                    <span>{eFieldNewUsedNames.join('，')}</span>
                </div>
            </WeaFormItem>
        ) : '';

        return (
            <div>
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@qjhsgi`} title={getLabel(81711, '基本信息')} needTigger={true} showGroup={true}>
                    <EType ecId={`${this && this.props && this.props.ecId || ''}_EType@v7ekk3`} ref="eType" value={this.props.eBaseName}/>
                    {this.props.eShareLevel == '2' ? <ETitle ecId={`${this && this.props && this.props.ecId || ''}_ETitle@9bghrw`} ref="eTitle" eid={this.props.eid} value={this.props.eTitle} {...this.props}/> : ''}
                    <EShowNum ecId={`${this && this.props && this.props.ecId || ''}_EShowNum@vxvfp8`} ref="eShowNum" value={this.props.eShowNum}/>
                    {EFieldNew}
                    <EShowHeader ecId={`${this && this.props && this.props.ecId || ''}_EShowHeader@xqpdt1`} ref="eShowHeader" value={this.props.showHeader}/>
                    {EShowSubordinates}
                </WeaSearchGroup>
            </div>
        );
    }

    getSaveValues() {
        return {
            eContentTitle: this.refs['eTitle'] ? this.refs['eTitle'].getSaveValues() : this.props.eTitle,
            eContentFieldNewUsedKeys: this.state.eFieldNewUsedKeys,
            eContentShowNum: this.refs['eShowNum'].getSaveValues(),
            eContentShowSubordinates: this.state.eShowSubordinates,
            eContentShowHeader: this.refs['eShowHeader'].getSaveValues(),
            eContentTabWidth: {tabwidth: this.props.etabwidth, methodvalue: this.props.methodvalue},
            eContenteTabStyle: {tabstyle: this.props.tabstyle, tabvalue: this.props.tabvalue, tabname: this.props.tabname},
        };
    }
}